﻿package mortal.game.view.copy.towerCopy.panel
{
    import __AS3__.vec.*;
    import com.gengine.resource.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import flash.display.*;
    import flash.geom.*;
    import flash.utils.*;
    import frEngine.primitives.object2d.*;
    import mortal.component.gconst.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.manager.window3d.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.copy.towerCopy.*;
    import mortal.game.view.copy.towerCopy.other.*;
    import mortal.game.view.guide.*;

    public class TowerPassInfoPanel extends GSprite
    {
        private var items:Vector.<TowerPassInfoItem>;
        private var passInfoEnter:TowerPassInfoEnterPanel;
        private var bgImg2D:Img2D;
        private var bgData:BitmapData;
        private var _indexArr:Array;
        private var _bigguanTipArr:Array;
        private var _bigPosArr:Array;
        protected var _window:Window;
        private var _isFresh:Boolean = false;
        private var _freshTime:uint = 0;
        public static const showMaxItems:int = 20;

        public function TowerPassInfoPanel(param1:Window)
        {
            this.items = new Vector.<TowerPassInfoItem>;
            this._indexArr = [0, 4, 9, 14, 19];
            this._bigPosArr = [[26, 492], [231, 422], [70, 192], [371, 369], [355, 30]];
            this._window = param1;
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            var _loc_3:TowerPassInfoItem = null;
            var _loc_4:TowerBigGanTipPanel = null;
            super.createDisposedChildrenImpl();
            var _loc_1:int = 0;
            while (_loc_1 < showMaxItems)
            {
                
                _loc_3 = this.createItem();
                addChild(_loc_3);
                this.items.push(_loc_3);
                this.items[_loc_1].passIndex = -1;
                this.items[_loc_1].MouseOver = this.onMouseOver;
                this.items[_loc_1].MouseOut = this.onMouseOut;
                _loc_1++;
            }
            this._bigguanTipArr = [];
            var _loc_2:int = 0;
            while (_loc_2 < 5)
            {
                
                _loc_4 = UIFactory.getUICompoment(TowerBigGanTipPanel, this._bigPosArr[_loc_2][0], this._bigPosArr[_loc_2][1] + 65, TowerModule(this._window).contentTopOf3DSprite);
                _loc_4.updateGan(_loc_2);
                this._bigguanTipArr.push(_loc_4);
                _loc_2++;
            }
            this.passInfoEnter = UICompomentPool.getUICompoment(TowerPassInfoEnterPanel) as TowerPassInfoEnterPanel;
            TowerModule(this._window).contentTopOf3DSprite.addChild(this.passInfoEnter);
            this.passInfoEnter.visible = false;
            LoaderManager.instance.load(ImagesConst.tower_win_bg2 + ".swf", this.onLoad);
            return;
        }// end function

        private function onLoad(param1) : void
        {
            var _loc_2:* = TowerModule(this._window).get3DObject();
            if (_loc_2)
            {
                this.bgImg2D = new Img2D(null, param1.bitmapData as BitmapData, new Rectangle(0, 0, 640, 542), false);
                _loc_2.addImg(this.bgImg2D);
                this.refresh();
            }
            return;
        }// end function

        private function updateImgPosition() : void
        {
            this.items[0].imgX = 41;
            this.items[0].imgY = 409;
            this.items[1].imgX = 149;
            this.items[1].imgY = 469;
            this.items[2].imgX = 207;
            this.items[2].imgY = 488;
            this.items[3].imgX = 270;
            this.items[3].imgY = 476;
            this.items[4].imgX = 231;
            this.items[4].imgY = 321;
            this.items[5].imgX = 170;
            this.items[5].imgY = 339;
            this.items[6].imgX = 110;
            this.items[6].imgY = 317;
            this.items[7].imgX = 62;
            this.items[7].imgY = 285;
            this.items[8].imgX = 37;
            this.items[8].imgY = 233;
            this.items[9].imgX = 70;
            this.items[9].imgY = 96;
            this.items[10].imgX = 203;
            this.items[10].imgY = 161;
            this.items[11].imgX = 259;
            this.items[11].imgY = 179;
            this.items[12].imgX = 309;
            this.items[12].imgY = 206;
            this.items[13].imgX = 356;
            this.items[13].imgY = 244;
            this.items[14].imgX = 375;
            this.items[14].imgY = 233;
            this.items[15].imgX = 503;
            this.items[15].imgY = 330;
            this.items[16].imgX = 558;
            this.items[16].imgY = 310;
            this.items[17].imgX = 571;
            this.items[17].imgY = 258;
            this.items[18].imgX = 560;
            this.items[18].imgY = 203;
            this.items[19].imgX = 467;
            this.items[19].imgY = 25;
            return;
        }// end function

        public function refresh(param1:Boolean = false) : void
        {
            if (this.isDisposed)
            {
                return;
            }
            if (this._isFresh)
            {
                return;
            }
            this._isFresh = true;
            this._freshTime = setTimeout(this.realFresh, 500);
            return;
        }// end function

        private function realFresh() : void
        {
            var _loc_9:TowerPassInfoItem = null;
            var _loc_10:int = 0;
            var _loc_11:TowerBigGanTipPanel = null;
            clearTimeout(this._freshTime);
            this._freshTime = 0;
            this._isFresh = false;
            this.updateImgPosition();
            var _loc_1:int = -1;
            var _loc_2:int = 0;
            var _loc_3:* = Cache.instance.copy.tower.getCurrentLevel(TowerModule.copyCode) - 1;
            var _loc_4:* = _loc_3 % 5;
            var _loc_5:* = Math.floor(_loc_3 / 5);
            var _loc_6:int = 0;
            while (_loc_6 < showMaxItems)
            {
                
                _loc_9 = this.items[_loc_6];
                _loc_10 = this._indexArr.indexOf(_loc_6);
                if (_loc_10 != -1)
                {
                    _loc_9.passIndex = _loc_5 * 5 + _loc_2;
                    if (_loc_2 < _loc_4 || Cache.instance.copy.tower.getIsMaxLv(TowerModule.copyCode, (_loc_3 + 1)))
                    {
                        this.items[_loc_6].passed = true;
                    }
                    else
                    {
                        if (_loc_1 == -1)
                        {
                            _loc_1 = _loc_6;
                        }
                        this.items[_loc_6].passed = false;
                    }
                    _loc_2++;
                }
                else
                {
                    _loc_9.passIndex = -1;
                    _loc_9.passed = _loc_1 == -1 || _loc_1 > -1 && _loc_1 > _loc_6;
                }
                _loc_9.refresh(false);
                _loc_6++;
            }
            var _loc_7:* = int(_loc_3 / 5) * 5 + 1;
            var _loc_8:int = 0;
            while (_loc_8 < 5)
            {
                
                _loc_11 = this._bigguanTipArr[_loc_8] as TowerBigGanTipPanel;
                _loc_11.updateGan(_loc_7);
                _loc_7++;
                _loc_8++;
            }
            return;
        }// end function

        private function createItem() : TowerPassInfoItem
        {
            return UICompomentPool.getUICompoment(TowerPassInfoItem, TowerModule(this._window)) as TowerPassInfoItem;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            var _loc_5:TowerBigGanTipPanel = null;
            super.disposeImpl(param1);
            this._isFresh = false;
            if (this._freshTime != 0)
            {
                clearTimeout(this._freshTime);
                this._freshTime = 0;
            }
            var _loc_2:int = 0;
            while (_loc_2 < showMaxItems)
            {
                
                this.items[_loc_2].dispose(param1);
                _loc_2++;
            }
            this.items.length = 0;
            var _loc_3:int = 0;
            while (_loc_3 < this._bigguanTipArr.length)
            {
                
                _loc_5 = this._bigguanTipArr[_loc_3];
                _loc_5.dispose();
                _loc_3++;
            }
            this._bigguanTipArr = null;
            this.passInfoEnter.dispose(param1);
            this.passInfoEnter = null;
            var _loc_4:* = TowerModule(this._window).get3DObject();
            if (_loc_4 && this.bgImg2D)
            {
                _loc_4.removeImg(this.bgImg2D);
                this.bgImg2D = null;
            }
            this.bgImg2D = null;
            return;
        }// end function

        private function onMouseOver(param1:TowerPassInfoItem) : void
        {
            var _loc_4:TowerModule = null;
            var _loc_5:Rectangle = null;
            var _loc_2:* = param1.passIndex + 1;
            var _loc_3:* = Cache.instance.copy.tower.getPlayerMaxPass(TowerModule.copyCode);
            if (_loc_2 < _loc_3 || Cache.instance.copy.tower.getIsMaxLv(TowerModule.copyCode, _loc_3))
            {
                this.passInfoEnter.state = TowerEnterConst.HasPass;
            }
            else if (_loc_2 == (_loc_3 + 1))
            {
                this.passInfoEnter.state = TowerEnterConst.CurrentPass;
            }
            else
            {
                this.passInfoEnter.state = TowerEnterConst.UnPass;
            }
            this.passInfoEnter.level = _loc_2;
            if (Cache.instance.copy.tower.getCurrentLevel(TowerModule.copyCode) <= GameConst.TConstTowerMaxLevel)
            {
                _loc_4 = TowerModule(this._window);
                _loc_5 = _loc_4.rect;
                this.passInfoEnter.direction = GuideArrow.Left;
                this.passInfoEnter.x = _loc_5.x + param1.imgX + param1.imgWidth + 45;
                this.passInfoEnter.y = _loc_5.y + param1.imgY - 90 + param1.imgHeight / 2;
                this.passInfoEnter.showMe(param1);
                this.passInfoEnter.refresh();
            }
            else
            {
                this.passInfoEnter.hideMe(param1, true);
            }
            return;
        }// end function

        private function onMouseOut(param1:TowerPassInfoItem) : void
        {
            this.passInfoEnter.hideMe(param1);
            return;
        }// end function

    }
}
